<template>
    <div>
        <h2>医生信息列表显示</h2>
        <input type="button" value="添加医生" @click="addys">
        <br>
        名称<input v-model="obj.name" type="text">
        职称<select v-model="obj.job" name="" id="">
                            <option value="">请选择</option>
                            <option value="主治医师">主治医师</option>
                            <option value="主任">主任</option>
                            <option value="普通医师">普通医师</option>
                        </select>
        <input type="button" value="查询" @click="cha">
        <table class="table">
            <thead>
                <tr>
                    <td>医生</td>
                    <td>图片</td>
                    <td>科室</td>
                    <td>职称</td>
                    <td>第一执业医院</td>
                    <td>是否开通账号</td>
                    <td>类型</td>
                    <td>创建时间</td>
                    <td>更新时间</td>
                    <td>操作</td>
                </tr>
            </thead>
            <tbody>
                <tr v-for="i in data">
                    <td>{{i.name}}</td>
                    <td><img style="width: 60px; height: 40px;" :src="'https://localhost:7260'+i.img" alt=""></td>
                    <td>{{i.kname}}</td>
                    <td>{{i.job}}</td>
                    <td>{{i.yiyuan}}</td>
                    <td>{{i.zhanghao?"已开通":"未开通"}}</td>
                    <td>{{i.type}}</td>
                    <td>{{i.createdate.substring(0,10)}}</td>
                    <td>{{i.updatedate.substring(0,10)}}</td>
                    <td>
                        
                        <input type="button" value="删除" @click="del(i.id)">
                        <input type="button" value="查看医生简介" @click="ups(i.id)">
                    </td>
                </tr>
            </tbody>
        </table>
        <input type="button" value="首页" @click="getpage(1)">
        <input type="button" value="上一页" @click="getpage(2)">
        <input type="button" value="下一页" @click="getpage(3)">
        <input type="button" value="尾页" @click="getpage(4)">
        共{{ obj.pcount }}/{{ obj.index }}页，共{{ obj.count }}条，每页{{ obj.size }}条
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { onMounted, ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
const route= useRoute();
const router=useRouter();

onMounted(()=>{
    show();
})
const show=()=>{
    axios.get('https://localhost:7260/api/YiSheng/ShowYiSheng',{params:obj.value}).then(res=>{
        data.value=res.data.data;
        obj.value.count=res.data.count;
        obj.value.pcount=Math.ceil(obj.value.count/obj.value.size);
    })
}
const getpage=(i:any)=>{
    if(i==1){
        obj.value.index=1;
        show();
    }
    if(i==2&&obj.value.index>1){
        obj.value.index-=1;
        show();
    }
    if(i==3&&obj.value.index<obj.value.pcount){
        obj.value.index+=1;
        show();
    }
    if(i==4){
        obj.value.index=obj.value.pcount;
        show();
    }
}
const data=ref([{
      "id": 2,
      "name": "string",
      "kname": "string",
      "job": "string",
      "xueli": "string",
      "img": "string",
      "yiyuan": "string",
      "type": "string",
      "zhanghao": true,
      "createdate": "2025-02-18T09:46:24.494",
      "updatedate": "2025-02-18T09:46:24.494",
      "del": false
    }])
const obj=ref({
    index:1,
    size:2,
    name:'',
    job:'',
    count:0,
    pcount:0
})
const cha=()=>{
    obj.value.index=1;
    show();
}
const del=(id:any)=>{
    if(confirm('确认删除吗？'))
    axios.delete('https://localhost:7260/api/YiSheng/DelectYiSheng',{params:{id:id}}).then(res=>{
        if(res.data>0){
            alert('删除成功');
            show();
        }
        else{
            alert('失败');
        }
    })
}
const ups=(id:any)=>{
    router.push({
        path:'updateys',
        query:{id:id}
    })
}
const addys=()=>{
    router.push('/addys')
}
</script>

<style scoped>

</style>